package com.xhui.vimarket.zkplus.zul.attr.evt.rtime;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.metainfo.ComponentInfo;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Tree;
import org.zkoss.zul.Treeitem;

import com.xhui.crm.common.util.string.StrUtil;com.xhui.vimarket.zkplusui.vimarket.zkplus.zul.attr.mod.impl.Attrcom.xhui.vimarket.zkplusrt com.xhui.vimarket.zkplus.zul.attr.mod.impl.AttrSelectTreeComp;

/**
 * 
 * .
 * 
 * @版权：福富软件 版权所有 (c) 2011
 * @author g.huangwch
 * @version Revision 1.0.0
 * @see:
 * @创建日期：2011-10-14
 * @功能说明：
 *
 */
public class AttrTreeComposer extends AttrRtimeSelectComposer {
    /**
     * .
     */
    private static final long serialVersionUID = 1L;
    
    @Override
    public ComponentInfo doBeforeCompose(final Page page, final Component comp,
        final ComponentInfo info) {
        return info;
    }
    
    @Override
    public void doAfterCompose(final Component comp) throws Exception {
        super.doAfterCompose(comp);
    }
    
    @Override
    public Component getRootComp() {
        return this.self.getParent().getParent().getParent().getParent();
    }
    
    /**
     * onSelect.
     */
    public void onSelect() {
        //Bandbox bandbox = (Bandbox) this.self.getParent().getParent().getParent();
        Component rootComp = this.self.getParent().getParent().getParent().getParent();
        Textbox textbox = AttrSelectTreeComp.getTextbox(rootComp);
        final Treeitem selectedItem = ((Tree) this.self).getSelectedItem();
        if (selectedItem != null && !"".equals(StrUtil.strnull(selectedItem.getValue()))) { // 有选中值
            textbox
                .setAttribute(AttrBaseComp.COMP_PARAM1, StrUtil.strnull(selectedItem.getValue()));
            textbox
                .setAttribute(AttrBaseComp.COMP_PARAM2, StrUtil.strnull(selectedItem.getLabel()));
            textbox.setValue(selectedItem.getLabel());
            textbox.setTooltiptext(selectedItem.getLabel());
        } else {
            textbox.removeAttribute(AttrBaseComp.COMP_PARAM1);
            textbox.removeAttribute(AttrBaseComp.COMP_PARAM2);
            textbox.setValue("");
            textbox.setTooltiptext("");
        }
        super.onSelect();
    }
}
